package jxc.base.helper;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Calendar;

public class TimeGenerator {
	
	public static String getTimeString(int length){
		NumberFormat format =  new DecimalFormat("00");
		Calendar cal=Calendar.getInstance();
		String timeString=cal.get(Calendar.YEAR)+
			format.format(cal.get(Calendar.MONTH))
			+format.format(cal.get(Calendar.DAY_OF_MONTH))
			+format.format(cal.get(Calendar.HOUR_OF_DAY))
			+format.format(cal.get(Calendar.MINUTE))
			+format.format(cal.get(Calendar.SECOND));
		if(length>timeString.length())
			length=timeString.length();
		return timeString.substring(0, length);
	}
	
	public static String getTimeString(){
		NumberFormat format =  new DecimalFormat("00");
		Calendar cal=Calendar.getInstance();
		String timeString=cal.get(Calendar.YEAR)+"/"+
			format.format(cal.get(Calendar.MONTH))+"/"
			+format.format(cal.get(Calendar.DAY_OF_MONTH))+"  "
			+format.format(cal.get(Calendar.HOUR_OF_DAY))+":"
			+format.format(cal.get(Calendar.MINUTE))+":"
			+format.format(cal.get(Calendar.SECOND));
		return timeString;
	}
}
